﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using gametest.DxAPI;
using gametest.sprites;

namespace gametest.sprites
{
    public class trung: ConGa
    {
        private DxImageObject imgtrung = null;
      
        private RoTrung rotrung ;

        private const double SPEED = 0.2;
        private double direction = +1;
        public int Time = 5;
        public trung(DxInitGraphics g, RoTrung ro)
            : base(g)
        {
            imgtrung = new DxImageObject("Images\\egg.png", BitmapType.TRANSPARENT, 0xFFFFFF, graphics.DDDevice);

            rotrung=ro;
        }

        override public void Draw()
        {
            imgtrung.XPosition = X_Axis +25;
            imgtrung.YPosition = Y_Axis +25;
            imgtrung.DrawBitmap(graphics.RenderSurface);
        }

        override public void Restore(DxInitGraphics g)
        {
            graphics = g;
            imgtrung.RestoreSurface();
        }

        public void Move(double dLoopDuration)
    //        public void Move(long Time1, long Time2)
        {
          
            Y_Axis += direction * (SPEED * dLoopDuration);
            CheckCollision();
            if (Y_Axis > (graphics.Target.Height - imgtrung.Height))
            {

                Y_Axis = Y_Pad + 25;
                direction = +1;
            }
           
            //else if (Y_Axis == rotrung.YAxis)
            //{
            //    CheckCollision();
            //}
        }

        private void CheckCollision()
        {
            if (rotrung.XAxis <= X_Axis && X_Axis <= (rotrung.XAxis + rotrung.Width) &&
                rotrung.YAxis <= Y_Axis && Y_Axis <= (rotrung.YAxis + rotrung.Height))
            {
                rotrung.SetCollision();
                Y_Axis = Y_Pad + 25;
             
            }
        }
    }
}
